<!--<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>-->
<!--<%-->
<!--String path = request.getContextPath();-->
<!--String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";-->
<!--%>-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base href="<%=basePath%>">

    <title>员工信息表</title>
    <meta name="pragma" content="no-cache">
    <meta name="cache-control" content="no-cache">
    <meta name="expires" content="0">
    <!--	<%@include file="../../script.html" %>-->
    <link th:insert="~{views/script :: tiancai}"/>

</head>
<style type="text/css">
    body {
        font-size: 14px
    }
</style>
<body>
<div id="toolbar" style="padding:0 30px;">
    <b>员工姓名: </b><input class="easyui-textbox" id="name" type="text" name="name"
                        style="width:166px;height:35px;line-height:35px;"/>
    <a href="javascript:void(0);" id="searchBtn" class="easyui-linkbutton" iconCls="icon-search"
       data-options="selected:true" style="background-color:#00aa00;color:white">查询</a>
    <a href="javascript:void(0);" id="setBtn" class="easyui-linkbutton" iconCls="icon-reload"
       style="background-color:#00aa00;color:white;margin-left:10px">重置</a>
    <a href="javascript:void(0);" onclick="return add('manage/employee/EmployeeAction_add.action')"
       class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true"
       style="background-color:#00aa00;color:white;margin-left:10px">添加</a>
    <a href="javascript:void(0);" onclick="return remove('manage/employee/EmployeeAction_remove.action')"
       class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true"
       style="background-color:#f00;color:white;margin-left:10px">删除</a>
    <a href="javascript:void(0);" onclick="return edit('manage/employee/EmployeeAction_edit.action')" id="editBtn"
       class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"
       style="background-color:#00aa00;color:white;margin-left:10px">修改</a>
</div>
<table id="empList" class="easyui-datagrid" style="font-size:14px"></table>
<script type="text/javascript">
    //为查询按钮添加处理函数
    $("#searchBtn").on("click", function () {
        var name = $("#name").val();
        "static/easyui/uimaker/easyui.css"
        $("#empList").datagrid("load", {"emp.name": name});

    })

    //为添加按钮添加事件处理函数
    function add(url) {
        parent.openTopWindow({
            title: "添加员工信息",
            width: 550,
            height: 500,
            "url": url,
            close: function () {
                $("#empList").datagrid("reload");
            }
        });
    }

    //为重置按钮添加事件处理函数
    $("#setBtn").on("click", function () {
        $("#empList").datagrid("load", {"emp.name": ""});
    })

    //修改按钮事件处理函数
    function edit(url) {
        var rows = $("#empList").datagrid("getChecked");
        if (!rows.length) {
            $.messager.alert("提示", "请选择需要修改的权限信息");
            return false;
        }

        if (rows.length >= 2) {
            $.messager.alert("提示", "一次只能选择修改一条产品信息");
            return false;
        }

        var empId = rows[0].empid;
        parent.openTopWindow({
            title: "修改员工信息",
            width: 550,
            height: 500,
            "url": url + "?id=" + empId,
            close: function () {
                $("#empList").datagrid("reload");
            }
        });
    }

    //删除按钮事件处理函数
    function remove(url) {
        //获取到选中的一行数据
        var rows = $("#empList").datagrid("getChecked");

        if (!rows.length) {
            $.messager.alert("警告", "请选择要删除的数据");
            return;
        }

        $.messager.confirm("警告", "数据删除后无法恢复，是否确认删除", function (b) {
            if (b) {
                var ids = new Array();
                $.each(rows, function (index, obj) {
                    ids.push(obj.empid);
                });
                //将数组中元素使用,分割拼接为一个字符串
                ids = ids.join(",");
                $.post(url,
                    {
                        "ids": ids
                    },
                    function (data) {
                        if (data && data.success) {
                            $.messager.alert("提示", data.message);
                            $("#empList").datagrid("reload");
                            return;
                        }
                        $.messager.alert("警告", data.message);
                    }, "json");
            }
        });
    }

    //加载用户数据
    $(function () {
        $("#empList").datagrid({
            url: "manage/employee/EmployeeAction_findByPage.action",
            pagination: true,
            toolbar: "#toolbar",
            fitColumns: true,
            idField: "empid",
            rownumbers: true,
            //singleSelect:true,
            columns: [[
                {field: "empid", title: "选择", checkbox: true},
                {field: "name", title: "员工姓名", sortable: true, width: 10},
                {field: "telephone", title: "联系电话", sortable: true, width: 10},
                {field: "email", title: "邮箱", sortable: true, width: 10},
                {field: "address", title: "地址", width: 10},
            ]],
            loadFilter: function (data) {
                //data是服务器返回的数据,将服务器端返回的数据转换为datagrid需要的格式
                return {"total": data.data.totalRows, "rows": data.data.result};
            }

        });
    });
</script>
</body>
</html>
